package com.iwhalecloud.citybrain.flow.platform.manager.application.service.impl;

import java.util.Date;

import com.iwhalecloud.citybrain.flow.platform.manager.application.service.SerialNumGenerator;
import org.apache.commons.lang3.RandomStringUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.time.DateFormatUtils;
import org.springframework.stereotype.Service;

/**
 * @author lilh
 * @date 2019-05-23 10:41
 */
@Service
public class SerialNumGeneratorImpl implements SerialNumGenerator {

    @Override
    public String generate(String prefix) {
        String suffix = DateFormatUtils.format(new Date(), "yyyyMMdd") + RandomStringUtils.random(8, false, true);
        return StringUtils.isEmpty(prefix) ? suffix : prefix + suffix;
    }

    @Override
    public String generate() {
        return generate(null);
    }
}
